package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.GuideDao;
import com.bysj.dao.impl.GuideDaoImpl;
import com.bysj.entity.Guide;
import com.bysj.entity.RenCai;
import com.bysj.service.GuideService;

public class GuideServiceImpl implements GuideService{
	private GuideDao gd=new GuideDaoImpl();
	@Override
	public void addGuide(Guide g) {
		String sql="insert into guide(title,type,content,time) values(?,?,?,?)";
		gd.addGuide(sql, g);
	}

	@Override
	public void DelGuide(Guide g) {
		String sql="delete from guide where id=?";
		gd.delGuide(sql, g);
		
	}

	@Override
	public void updateGuide(Guide g) {

	}

	@Override
	public ArrayList<Guide> queryAllGuide() {
		return null;
	}

	@Override
	public int CountAllGuide() {
		String sql="select count(*) from guide";
		return gd.CountGuide(sql);
	}

	@Override
	public ArrayList<Guide> FenyequeryGuide(int page, int rows) {
		String sql="select id,title,type,content,time,docname from guide limit ?,?";
		return gd.FenyeQuery(sql, page, rows);
	}

	@Override
	public ArrayList<Guide> queryGuideByType(Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where type= ?";
		return gd.queryGuideByType(sql,guide);
	}

	@Override
	public Guide queryGuide(Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where id= ?";
		return gd.queryGuideByid(sql,guide);
	}

	@Override
	public void updateGuideDocById(Guide g) {
		String  sql="update guide set docname=? where id=?";
		gd.updateGuideDocById(sql,g);
	}

	@Override
	public ArrayList<Guide> queryLikeByTitle(String title) {
		String sql="select id,title,type,content,time,docname from guide where title like '%"+title+"%' or content like '%"+title+"' or time like '%"+title+"%'";
		return gd.queryGuideLikeByTitle(sql);
	}

	@Override
	public int CountAllGuideBytitle(Guide guide) {
		String sql="select count(*) from guide where title like '%"+guide.getTitle()+"%'";
		return gd.CountGuide(sql);
	}

	@Override
	public int CountAllGuideBycontent(Guide guide) {
		String sql="select count(*) from guide where content like '%"+guide.getContent()+"%'";
		return gd.CountGuide(sql);
	}

	@Override
	public int CountAllGuideBytime(Guide guide) {
		String sql="select count(*) from guide where time like '%"+guide.getTime()+"%'";
		return gd.CountGuide(sql);
	}

	@Override
	public ArrayList<Guide> FenyeQueryBytitle(int page, int rows,
			Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where title like'%"+guide.getTitle()+"%' limit ?,?";
		return gd.FenyeQuery(sql, page, rows);
	}

	@Override
	public ArrayList<Guide> FenyeQueryByContent(int page, int rows,
			Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where content like '%"+guide.getContent()+"%'limit ?,?";
		return gd.FenyeQuery(sql, page, rows);
	}

	@Override
	public ArrayList<Guide> FenyeQueryByTime(int page, int rows,
			Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where time like '%"+guide.getTime()+"%' limit ?,?";
		return gd.FenyeQuery(sql, page, rows);
	}

	@Override
	public ArrayList<Guide> FenyeQueryByType(int nowPage, int pageRowNum,
			Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where type like '%"+guide.getType()+"%' limit ?,?";
		return gd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<Guide> FenyeQueryById(int nowPage, int pageRowNum,
			Guide guide) {
		String sql="select id,title,type,content,time,docname from guide where id like '%"+guide.getId()+"%' limit ?,?";
		return gd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public int CountGuideById(Guide guide) {
		String sql="select count(*) from guide where id like '%"+guide.getId()+"%'";
		return gd.CountGuide(sql);
	}

	@Override
	public int CountGuideByType(Guide guide) {
		String sql="select count(*) from guide where type like '%"+guide.getType()+"%'";
		return gd.CountGuide(sql);
	}

}
